function onInitialize() {
	setupUi();
}

function setupUi() {
	$('#btnStart').click(function() {
	    onEnable();
	    $(this).hide();
	    $('#btnStop').show();
	});

	$('#btnStop').click(function() {
	    onDisable();
	    $(this).hide();
	    $('#btnStart').show();
	});
}

function onEnable() {
    //console.write("Called reload tab");
		chrome.tabs.getSelected(null, function(tab) {
		    chrome.extension.sendMessage({ tab: tab, refresh: true, connectToSignal: true }, function (response)
		    {
		        //console.write(response);
		        alert(response.stopData);
		    });
			window.close();
		});
}

function onDisable() {
		chrome.tabs.getSelected(null, function(tab) {
			chrome.extension.sendMessage({ tab: tab, refresh: false, connectToSignal: false }, function (response)
			{
			    //console.write(response);
			    alert(response.stopData);
			});
			window.close();
		});
}

function onDomain() {
    chrome.tabs.getSelected(null, function (tab) {
        localStorage.removeItem(tab.url);
		});
}

// Hack to make focusing on a text field work in Chrome. Yes, it actually works. http://code.google.com/p/chromium/issues/detail?id=111660#c7
if (location.search !== "?foo") {
  location.search = "?foo";
  throw new Error;  // load everything on the next page;
                    // stop execution on this page
}